package com.vim.modules.mall.service.impl;

import com.github.pagehelper.PageInfo;
import com.vim.common.utils.AssertUtils;
import com.vim.modules.mall.model.base.CommonPage;
import com.vim.modules.mall.model.base.MallResponseEntity;
import com.vim.modules.mall.model.base.Page;
import com.vim.modules.mall.model.base.PageConvertUtils;
import com.vim.modules.mall.model.mallGoods.MallGoods;
import com.vim.modules.mall.model.mallGoods.MallGoodsType;
import com.vim.modules.mall.service.MallGoodsService;
import com.vim.modules.mall.service.remote.RemoteMallGoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @作者 Administrator
 * @时间 2020-10-04 19:10
 * @版本 1.0
 */
@Service
public class MallGoodsServiceImpl implements MallGoodsService {

    @Autowired
    private RemoteMallGoodsService remoteMallGoodsService;

    /**
     * 获取商品列表
     */
    @Override
    public PageInfo<MallGoods> goodsList(Page page, String goodsName) {
        MallResponseEntity<CommonPage<MallGoods>> result = remoteMallGoodsService.goodsList(goodsName, page.getPageNo(), page.getPageSize());
        AssertUtils.assertAjaxOK(result);
        return PageConvertUtils.convert(result.getData());
    }

    /**
     * 获取商品信息
     * @param id 商品id
     */
    @Override
    public MallGoods goodsInfo(Long id) {
        MallResponseEntity<MallGoods> result = remoteMallGoodsService.goodsInfo(id);
        AssertUtils.assertAjaxOK(result);
        return result.getData();
    }

    /**
     * 商品保存
     * @param goodsInfo 商品信息json串
     */
    @Override
    public void goodsSave(String goodsInfo) {
        MallResponseEntity result = remoteMallGoodsService.goodsSave(goodsInfo);
        AssertUtils.assertAjaxOK(result);
    }

    /**
     * 获取商品分类信息
     * @param id 分类id
     */
    @Override
    public MallGoodsType goodsTypeInfo(Long id) {
        MallResponseEntity<MallGoodsType> result = remoteMallGoodsService.goodsTypeInfo(id);
        AssertUtils.assertAjaxOK(result);
        return result.getData();
    }

    /**
     * 获取商品分类列表
     */
    @Override
    public List<MallGoodsType> goodsTypeList() {
        MallResponseEntity<List<MallGoodsType>> result = remoteMallGoodsService.goodsTypeList();
        AssertUtils.assertAjaxOK(result);
        return result.getData();
    }

    /**
     * 获取商品分类列表
     * @param pid   父级分类id
     */
    @Override
    public List<MallGoodsType> goodsTypeListWithParent(Long pid) {
        MallResponseEntity<List<MallGoodsType>> result = remoteMallGoodsService.goodsTypeListWithParent(pid);
        AssertUtils.assertAjaxOK(result);
        return result.getData();
    }
}
